<?php


namespace app\common\service\agent;


use think\facade\Db;

class SettingService
{

    public function getSliderAndVajra($agent_id,$type=1){
        // 获取轮播图
        $slider = Db::name('takeout_slider')
            ->field('name, image, params')
            ->where('agent_id', $agent_id)
            ->where('type', $type)
            ->where('is_deleted', 0)
            ->where('status', 1)
            ->order('sort desc, id desc')
            ->select()
            ->toArray();
        foreach ($slider as $k => $v) {
            $params = json_decode($v['params'], true);
            $slider[$k]['type'] = $params['type'];
            // if (!in_array($params['type'], [0, 99])) {
            //     $slider[$k]['url'] = $params['path'] . '?channel='.$request->agentChannel['name'];
            // } else {
            //     $slider[$k]['url'] = $params['path'];
            // }
            $slider[$k]['url'] = $params['path'];
            unset($slider[$k]['params']);
        }

        // 获取金刚区
        $vajra = Db::name('takeout_vajra')
            ->field('name, image, params')
            ->where('agent_id', $agent_id)
            ->where('is_deleted', 0)
            ->where('type', $type)
            ->where('status', 1)
            ->order('sort desc, id desc')
            ->select()
            ->toArray();
        foreach ($vajra as $k => $v) {
            $params = json_decode($v['params'], true);
            $vajra[$k]['type'] = $params['type'];
            // if (!in_array($params['type'], [0, 99])) {
            //     $vajra[$k]['url'] = $params['path'] . '?channel='.$request->agentChannel['name'];
            // } else {
            //     $vajra[$k]['url'] = $params['path'];
            // }
            $vajra[$k]['url'] = $params['path'];
            unset($vajra[$k]['params']);
        }

        return [
            'slider' => $slider,
            'JGList' => $vajra,
        ];
    }
}